package com.wbcs.system.component.application.report.configbean.editablereport;

import java.util.List;
import java.util.Map;

import com.wbcs.config.component.application.report.ReportBean;
import com.wbcs.exception.WbcsConfigLoadingException;
import com.wbcs.system.ReportRequest;
import com.wbcs.system.component.application.report.EditableListReportType;
import com.wbcs.util.Tools;

public class EditableListReportInsertDataBean extends EditableReportInsertDataBean
{
    private EditableListReportInsertUpdateBean realInsertBean;

    public EditableListReportInsertDataBean(IEditableReportEditGroupOwnerBean owner)
    {
        super(owner);
    }

    public EditableListReportInsertUpdateBean getRealInsertBean()
    {
        return realInsertBean;
    }

    public void setRealInsertBean(EditableListReportInsertUpdateBean realInsertBean)
    {
        this.realInsertBean=realInsertBean;
    }

    @Override
	public int parseActionscripts(String reportTypeKey)
    {
        if(this.realInsertBean.getLstUrlParams()!=null)
        {
            String paramValueTmp;
            for(Map<String,String> mParamTmp:this.realInsertBean.getLstUrlParams())
            {
                if(mParamTmp==null||mParamTmp.size()==0) continue;
                paramValueTmp=mParamTmp.entrySet().iterator().next().getValue();
                if(Tools.isDefineKey("url",paramValueTmp))
                {
                    throw new WbcsConfigLoadingException("加载报表"+this.getOwner().getReportBean().getPath()
                            +"失败，editablelist报表类型的<insert/>中urlparams参数不能配置为url{name}，可以配置为request/session{key}格式");
                }
                if(Tools.isDefineKey("@",paramValueTmp))
                {
                    throw new WbcsConfigLoadingException("加载报表"+this.getOwner().getReportBean().getPath()
                            +"失败，editablelist报表类型的<insert/>中urlparams参数不能配置为@{name}，即不能从某列获取参数值，可以配置为request/session{key}格式");
                }
            }
        }
        return 1;
    }

    public String parseUpdateWhereClause(ReportBean rbean,String reportKey,List<EditableReportParamBean> lstDynParams,String whereclause)
    {
        return "";
    }

    public String assembleAccessPageUrl(ReportRequest rrequest,EditableListReportType reportTypeObj,Object dataObj)
    {
        return this.realInsertBean.assembleAccessPageUrl(rrequest,reportTypeObj,dataObj);
    }

    public void doPostLoad()
    {
        this.realInsertBean.doPostLoad();
    }

    @Override
	public Object clone(IEditableReportEditGroupOwnerBean newowner)
    {
        EditableListReportInsertDataBean newbean=(EditableListReportInsertDataBean)super.clone(newowner);
        if(this.realInsertBean!=null)
        {
            newbean.setRealInsertBean((EditableListReportInsertUpdateBean)realInsertBean.clone(newbean));
        }
        return newbean;
    }
}
